package com.wiloon.androidx;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;

import com.j256.ormlite.android.apptools.OpenHelperManager;
import com.wiloon.androidx.dao.DatabaseHelper;
import com.wiloon.androidx.utils.CommonUtils;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import java.io.File;

import de.mindpipe.android.logging.log4j.LogConfigurator;

public class BaseActivity extends Activity {
    private volatile DatabaseHelper databaseHelper;

    static {
        initLogger();
    }

    public static void initLogger() {
        Log.d("Base Activity", "init logger");
        try {
            final LogConfigurator logConfigurator = new LogConfigurator();
            logConfigurator.setFileName(Environment.getExternalStorageDirectory() + File.separator + "androidx/androidx.log");
            // Set the root log level
            logConfigurator.setRootLevel(Level.DEBUG);
            // Set log level of a specific logger
            logConfigurator.setLevel("org.apache", Level.ERROR);
            logConfigurator.setMaxFileSize(5 * 1024 * 1024);
            logConfigurator.setMaxBackupSize(1);
            logConfigurator.configure();
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("Base action.", "failed to init logger.");
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }



    public DatabaseHelper getDatabaseHelper() {
        if (databaseHelper == null) {
            databaseHelper = (DatabaseHelper) OpenHelperManager.getHelper(this, DatabaseHelper.class);
        }
        return databaseHelper;
    }
}
